package mysql

import (
	"database/sql"
	"fmt"
)

// 往数据库记录数据
func InsertSource(db *sql.DB, ip string, time string, source string) bool {

	//准备sql语句
	insertStr := fmt.Sprintf(`INSERT into %s set time=?,source=?`, ip)
	stmt, PrepareErr := db.Prepare(insertStr)
	if PrepareErr != nil {
		fmt.Println("Prepare fail")
		return false
	}
	//设置参数以及执行sql语句
	var _, execErr = stmt.Exec(time, source)
	if execErr != nil {
		fmt.Println(execErr)
		return false
	}
	return true

}
